package top.z.template.parse.ast;

import top.z.template.Context;
import top.z.template.Template;
import top.z.template.parse.Ast.Node;
import top.z.template.parse.Span;

import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

/**
 * 文本节点, 原样输出内容
 */
public class Text extends Node {

    private final byte[] value;

    public Text(Span text) {
        super(text);
        value = text.getText().getBytes(StandardCharsets.UTF_8);
    }

    public byte[] getValue() {
        return value;
    }

    @Override
    public Object evaluate(Template template, Context context, OutputStream out) throws IOException {
        out.write(getValue());
        return null;
    }

}